package com.spoj;

import java.util.Scanner;
import java.math.BigInteger;
public class ARITH{

    public static BigInteger karatsuba(BigInteger x, BigInteger y) {

        // cutoff to brute force
        int N = Math.max(x.bitLength(), y.bitLength());
        if (N <= 10) return x.multiply(y);                // optimize this parameter

        // number of bits divided by 2, rounded up
        N = (N / 2) + (N % 2);

        // x = a + 2^N b,   y = c + 2^N d
        BigInteger b = x.shiftRight(N);
        BigInteger a = x.subtract(b.shiftLeft(N));
        BigInteger d = y.shiftRight(N);
        BigInteger c = y.subtract(d.shiftLeft(N));

        // compute sub-expressions
        BigInteger ac    = karatsuba(a, c);
        BigInteger bd    = karatsuba(b, d);
        BigInteger abcd  = karatsuba(a.add(b), c.add(d));

        return ac.add(abcd.subtract(ac).subtract(bd).shiftLeft(N)).add(bd.shiftLeft(2*N));
    }
    public static String dummyString(char c, long length) {
    	int len = (int) length;
	  	if( len < 1 ) return "";
	 	StringBuilder sb = new StringBuilder(len).append(c);
	  	int remnant = len - sb.length(); 
	  	while(remnant  > 0) {
	  		 if( remnant  >= sb.length() ) sb.append(sb);
	   		else sb.append(sb.subSequence(0, remnant));
	   		remnant  = len - sb.length();
	 	}
	 	 return sb.toString();
	}
	public static void main(String[] args) {
		try{
			Scanner input = new Scanner(System.in);
			long number = input.nextInt();
			for(long i = 0; i < number ; i++){
				String inputString = input.next();
				if(inputString.contains("+")){
					String firstNum = inputString.substring(0,inputString.indexOf("+"));
					String secondNum = inputString.substring(inputString.indexOf("+")+1,inputString.length());
					BigInteger first = new BigInteger(firstNum);
					BigInteger second = new BigInteger(secondNum);
					BigInteger finalNumber = first.add(second);
					long finalLength = finalNumber.toString().length();
					long maxLength = finalLength;
					if(secondNum.length() == maxLength){
						maxLength = maxLength + 1;
					}
					long firstDiff = maxLength - firstNum.length();
					long secondDiff = maxLength - secondNum.length();
					System.out.print(dummyString(" ".charAt(0),firstDiff));
					System.out.println(firstNum);
					System.out.print(dummyString(" ".charAt(0),secondDiff-1));
					System.out.println("+" + secondNum);
					System.out.print(dummyString("-".charAt(0),maxLength));
					System.out.println();
					System.out.print(dummyString(" ".charAt(0),maxLength-finalLength));
					System.out.println(finalNumber);	
				}else if(inputString.contains("-")){
					String firstNum = inputString.substring(0,inputString.indexOf("-"));
					String secondNum = inputString.substring(inputString.indexOf("-")+1,inputString.length());
					BigInteger first = new BigInteger(firstNum);
					BigInteger second = new BigInteger(secondNum);
					BigInteger finalNumber = first.subtract(second);
					long finalLength = finalNumber.toString().length();
					long maxLength = firstNum.length();
					if(firstNum.length() == secondNum.length()){
						maxLength = maxLength + 1;
					}
					long firstDiff = maxLength - firstNum.length();
					long secondDiff = maxLength - secondNum.length();
					System.out.print(dummyString(" ".charAt(0),firstDiff));
					System.out.println(firstNum);
					System.out.print(dummyString(" ".charAt(0),secondDiff-1));
					System.out.println("-" + secondNum);
					System.out.print(dummyString("-".charAt(0),maxLength));
					System.out.println();
					System.out.print(dummyString(" ".charAt(0),maxLength-finalLength));
					System.out.println(finalNumber);
				}
				else if(inputString.contains("*")){
					String firstNum = inputString.substring(0,inputString.indexOf("*"));
					String secondNum = inputString.substring(inputString.indexOf("*")+1,inputString.length());
					BigInteger first = new BigInteger(firstNum);
					BigInteger second = new BigInteger(secondNum);
					int firstLength = firstNum.length();
					int secondLength = secondNum.length();
					BigInteger finalNumber = karatsuba(first,second);
					long finalLength = finalNumber.toString().length();
					String partialAns = "";
					long firstDiff = finalLength - firstLength;
					if(finalLength == secondLength){
						firstDiff += 1;
					}
					long secondDiff = finalLength - secondLength;
					System.out.print(dummyString(" ".charAt(0),firstDiff));
					System.out.println(firstNum);
					System.out.print(dummyString(" ".charAt(0),secondDiff-1));
					System.out.println("*" + secondNum);
					if(secondLength > 1){
						long length = (firstLength > secondLength + 1)  ? firstNum.length() : (secondLength + 1);
						for(int j=0;j<secondLength; j++){
							partialAns = karatsuba(first,new BigInteger(Character.toString(secondNum.charAt(secondLength-j-1)))).toString();
							if(j==0){
								if(partialAns.length() > length){
									length = partialAns.length();
								}
								System.out.print(dummyString(" ".charAt(0),finalLength - length));
								System.out.print(dummyString("-".charAt(0),length));
								System.out.println();
							}
							System.out.print(dummyString(" ".charAt(0),finalLength - partialAns.length() - j));
							System.out.print(partialAns);
							System.out.print(dummyString(" ".charAt(0),i));
							System.out.println();
						}
					}
					System.out.print(dummyString("-".charAt(0),finalLength));
					System.out.println();
					System.out.println(finalNumber);
				}
				System.out.println();
			}
			input.close();
		}catch(Exception e){
			return;
		}
	} 
}